package com.evidencer.demo.servlet;
/**
 * @Title: HelloWorld.java
 * @Package 
 * @Description: TODO
 * @author lyz lyzpoq_gmail_com
 * @date 2014/01/08 15:22:58
 * @version V1.0
 */
// Import required java libraries
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static com.evidencer.java.utils.Printer.sop;

// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
 
  private String message;
  private static int count=0;

  public void init() throws ServletException
  {
      // Do required initialization
	  System.out.println("init Run....."+ ++count);
      message = "Hello World";
  }

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
            throws ServletException, IOException
  {
	  System.out.println("doGet Run....."+ ++count);
	  // Set response content type 
	  // http://localhost:8088/HelloForm?first_name=ZARA&last_name=ALI
      response.setContentType("text/html");

      PrintWriter out = response.getWriter();
	  String title = "Using GET Method to Read Form Data";
      String docType =
      "<!doctype html public \"-//w3c//dtd html 4.0 " +
      "transitional//en\">\n";
      out.println(docType +
                "<html>\n" +
                "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f0f0f0\">\n" +
                "<h1 align=\"center\">" + title + "</h1>\n" +
                "<ul>\n" +
                "  <li><b>First Name</b>: "
                + request.getParameter("first_name") + "\n" +
                "  <li><b>Last Name</b>: "
                + request.getParameter("last_name") + "\n" +
                "</ul>\n" +
                "</body></html>");
      
//      // Set response content type
//      response.setContentType("text/html");
//
//      // Actual logic goes here.
//      PrintWriter out = response.getWriter();
//      out.println("<h1>" + message + "</h1>");
  }
  
  public void destroy()
  {
	  super.destroy();
	  System.out.println("destroy Run....."+ ++count);
      // do nothing.
  }

/**
*Title: doPost
*Description: 
* @param req
* @param resp
* @throws ServletException
* @throws IOException
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	super.doPost(req, resp);
	 System.out.println("doPost Run....."+ ++count);
	
}

/**
*Title: service
*Description: 
* @param arg0
* @param arg1
* @throws ServletException
* @throws IOException
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/

@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	//super.service(arg0, arg1);
	sop(arg1.getStatus(),"arg1.getStatus()");
	System.out.println("service Run....."+ ++count);
	
}

  
}

